package cn.sccl.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;

import cn.sccl.dao.CustomerDao;
import cn.sccl.domain.Customer;
import cn.sccl.utils.HibernateUtils;

/**
 * @author 饶爽
 * @time 2019年8月24日 下午3:55:00
 * @version 1.0.0
 * Customer数据库访问实现类
*/
public class CustomerDaoImpl implements CustomerDao {

    public void save(Customer customer) {
        //1.获得session
        Session session = HibernateUtils.getCurrentSession();
        //3.执行保存
        session.save(customer);
    }

	@Override
	public List<Customer> getAll() {
		//1.获得session
        Session session = HibernateUtils.getCurrentSession();
        //2.获取查询结果Criteria
        Criteria c = session.createCriteria(Customer.class);
		return c.list();
	}

    @Override
    public Customer getById(Long cust_id) {
        //获得session
        Session session = HibernateUtils.getCurrentSession();
        return session.get(Customer.class, cust_id);
    }

    @Override
    public List<Customer> getAll(DetachedCriteria dc) {
        //获得session
        Session session = HibernateUtils.getCurrentSession();
        //关联离线Criteria到session
        Criteria ct= dc.getExecutableCriteria(session);
        return ct.list();
    }
    
}
